/* enum */
import AuthEnum from "@model/enum/AuthEnum"
/* model */
import Auth from "@model/entity/Auth"
/* util */
import { hasAuth } from "@src/util/auth"
import { getRootWindowInitData } from '@src/util/window'
import { getRootWindow } from '@src/util/dom';

function isHaveCallCenterViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.CALL_CENTER_VIEW_DETAIL)
}

function isHaveCallCenterExportAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.CALL_CENTER_EXPORT)
}

function isHaveCallCenterEditAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.CALLCENTER_EDIT)
}

function isHaveImViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.CASE_CONVERSATION_DETAIL)
}

function isHaveEventViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.CASE_VIEW_DETAIL)
}

function isHaveCustomerViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.CUSTOMER_VIEW_DETAIL)
}

function isHaveProductViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.PRODUCT_VIEW_DETAIL)
}

function isHaveProductCatalogViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.PRODUCT_CATALOG_VIEW_DETAIL)
}

function isHaveTaskViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.TASK_VIEW_DETAIL)
}

function isHaveAccountViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.ACCOUNT_VIEW)
}

function isHaveUserViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.ACCOUNT_VIEW)
}

function isHaveTaskPlanViewDetailAuth(auth: Auth): boolean {
  return hasAuth(auth, AuthEnum.TASK_PLAN_VIEW_DETAIL)
}

/**
 * 查看门户页面
 */
function isHavePortalPageViewAuth(): boolean {
  const RootWindow = getRootWindow(window);
  if(!RootWindow.grayAuth?.DOOR_MENU) return true // 没开灰度默认给权限
  const auth = getRootWindowInitData()?.user?.auth ?? {}
  return hasAuth(auth, AuthEnum.PORTAL_PAGE_VIEW)
}

/**
 * 设置门户页面
 */
function isHavePortalPageSetAuth(): boolean {
  const RootWindow = getRootWindow(window);
  if(!RootWindow.grayAuth?.DOOR_MENU) return true // 没开灰度默认给权限
  const auth = getRootWindowInitData()?.user?.auth ?? {}
  return hasAuth(auth, AuthEnum.PORTAL_PAGE_SET)
}
/**
 * 自定义报表权限
 */
function isHaveCustomReportPageSetAuth(): boolean {
  const RootWindow = getRootWindow(window);
  if(!RootWindow?.CUSTOM_REPORT) return false // 没开灰度默认给权限
  
  const auth = getRootWindowInitData()?.user?.auth ?? {}
  return hasAuth(auth, AuthEnum.VIP_REPORT_VIEW)
}

export {
  isHaveCallCenterViewDetailAuth,
  isHaveImViewDetailAuth,
  isHaveEventViewDetailAuth,
  isHaveCustomerViewDetailAuth,
  isHaveProductViewDetailAuth,
  isHaveProductCatalogViewDetailAuth,
  isHaveTaskViewDetailAuth,
  isHaveCallCenterExportAuth,
  isHaveCallCenterEditAuth,
  isHaveAccountViewDetailAuth,
  isHaveUserViewDetailAuth,
  isHaveTaskPlanViewDetailAuth,
  isHavePortalPageViewAuth,
  isHavePortalPageSetAuth,
  isHaveCustomReportPageSetAuth,
}

export default {
  isHaveCallCenterViewDetailAuth,
  isHaveImViewDetailAuth,
  isHaveEventViewDetailAuth,
  isHaveCustomerViewDetailAuth,
  isHaveProductViewDetailAuth,
  isHaveProductCatalogViewDetailAuth,
  isHaveTaskViewDetailAuth,
  isHaveCallCenterExportAuth,
  isHaveCallCenterEditAuth,
  isHaveAccountViewDetailAuth,
  isHaveUserViewDetailAuth,
  isHaveTaskPlanViewDetailAuth,
  isHavePortalPageViewAuth,
  isHavePortalPageSetAuth,
  isHaveCustomReportPageSetAuth,
}